import processing.core.PApplet;
import processing.core.*;



public class Circle extends Node {	
	//appearance
	String name;		
	float radius;	
	
	//dynamics	
	float[] direction = new float[2]; //[x,y]
	
	final float c = 200.0f; //some constant for timesteps
		
	//constructor
	public Circle(PApplet sketch, float[] position, int size){
		this.position = position.clone();
		setSize(size);
	}
	
	//constructor with name and color
	public Circle(PApplet sketch, float[] position, int size, String name, int color){
		this(sketch, position, size);
		this.name = name;
		this.color = color;
	}

	/**
	 * alter current direction by some force
	 */
	@Override
	public void exertForce(float[] force) {
		this.direction[0] += force[0]/mass;
		this.direction[1] += force[1]/mass;
	}
	
	/**
	 * Move one step in current direction
	 * @return the moved distance
	 */
	public float move(){
		this.position[0] += c * this.direction[0];
		this.position[1] += c * this.direction[1];
		//TODO: check with parent papplet for position.
		
		return c * (float) Math.sqrt(Math.pow(this.direction[0], 2) + 
				Math.pow(this.direction[1], 2));
	}

	@Override
	public void dampen() {
		float d = 0.4f;
		this.direction[0] *= d;
		this.direction[1] *= d;
		//in case something weird might happen:
		//TODO:think of somethin smarter than this.
		if (!(direction[0] < 10000f && direction[0] > -10000f)){
			direction[0] = 0f;
		}
		if (!(direction[1] < 10000f && direction[1] > -10000f)){
			direction[1] = 0f;
		}

	}

	public void setSize(int size) {		
		this.radius = 8 + 3 * size;
		this.mass = 0.1f* this.radius * this.radius;
	}

}
